<template>
  <a-modal
    :visible="visible"
    :width="400"
    :confirm-loading="loading"
    title="请输入要修改的税率"
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <a-input-number
      v-model="tax"
      placeholder=""
      size="large"
      :formatter="value => `${value}%`"
      :parser="value => value.replace('%', '')"
    ></a-input-number>
  </a-modal>
</template>

<script>
import { putAction } from '@api/manage'

export default {
  name: 'HandlePurchaseTaxModal',
  data() {
    return {
      visible: false,
      tax: null,
      loading: false,
      url: {
        changeTax: '/purchase/hfPurchaseprice/changeTax'
      }
    }
  },
  methods: {
    handleOk() {
      const formData = new FormData()
      formData.append('tax', this.tax)
      this.loading = true
      putAction(this.url.changeTax, formData)
        .then(res => {
          if (res.success) {
            this.$message.success('修改成功,当前税率为' + this.tax)
            this.handleCancel()
          } else {
            this.$message.error('修改失败')
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
    handleCancel() {
      this.visible = false
      this.tax = null
    }
  }
}
</script>

<style scoped></style>
